<?php

################################################################################################################
Function show_modules($start, $limit)
{
	$table_modules = $_SESSION['prefix']."modules";

	$connection = dbconnect();
	$req = dbquery("SELECT mid,name,description,actif,type,version FROM $table_modules WHERE 1 ORDER BY mid ASC LIMIT $start,$limit", $connection);
	if (@mysql_num_rows($req) == 0)
	{
		mysql_close($connection);
		return (-1);
    }
   
	while ($line = @mysql_fetch_array($req))
    {
		if ($line['actif'] == "ko")
			$class = "red";
		else
			$class = "blue";
			
			Print("
				<thead>
				<tr class=\"$class\">
					<td align=left><font color=green>$line[mid]</font></td>
					<td align=left><font color=darkblue><b>$line[name]</b></font></td>
					<td align=left valign=top>$line[description]</td>
					<td align=left valign=top>$line[type]</td>
					<td align=left valign=top>$line[version]</td>
			");
				if ($line['actif'] == "ok")
					$image = "$_SESSION[path_images]/valid.png";
				else
					$image = "$_SESSION[path_images]/stop.png";
			Print("
					<td align=center valign=top><img src=\"$image\"></td>
					<td align=center>
			");
			
			if ($line['type'] != "system")
			{
				if ($line['type'] == "user")
				{
					Print("
						<a href=\"ipage.php?height=400&act=edit&mid=$line[mid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Edition module</b></font>\"><img src=\"$_SESSION[current_path]/images/application_edit.png\" width=16 height=16 title=\"Modifier le module $line[name]\"></a> ' 
						<a href=\"ipage.php?height=550&act=rights&mid=$line[mid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Droits module</b></font>\"><img src=\"$_SESSION[current_path]/images/application_key.png\" width=16 height=16 title=\"G&eacute;rer les droits du module $line[name]\"></a> '
						<a href=\"ipage.php?height=200&act=delete&mid=$line[mid]\" class=\"thickbox\" title=\"<font color=red><b>Suppression module</b></font>\"><img src=\"$_SESSION[current_path]/images/application_delete.png\" width=16 height=16 title=\"Supprimer le module $line[name]\"></a>
					");
				}
				elseif ($line['type'] == "link")
				{
					Print("
						<a href=\"ipage.php?height=400&act=edit&mid=$line[mid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Edition lien</b></font>\"><img src=\"$_SESSION[current_path]/images/link_edit.png\" width=16 height=16 title=\"Modifier le lien $line[name]\"></a> ' 
						<a href=\"ipage.php?height=550&act=rights&mid=$line[mid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Droits lien</b></font>\"><img src=\"$_SESSION[current_path]/images/link.png\" width=16 height=16 title=\"G&eacute;rer les droits du lien $line[name]\"></a> '
						<a href=\"ipage.php?height=200&act=delete&mid=$line[mid]\" class=\"thickbox\" title=\"<font color=red><b>Suppression lien</b></font>\"><img src=\"$_SESSION[current_path]/images/link_delete.png\" width=16 height=16 title=\"Supprimer le lien $line[name]\"></a>
					");
				}
			}
			
			if (($line['type'] == "system") && (is_root($_SESSION['login'], $connection)))
			{
				Print("
					<a href=\"ipage.php?height=400&act=edit&mid=$line[mid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Edition module</b></font>\"><img src=\"$_SESSION[current_path]/images/application_edit.png\" width=16 height=16 title=\"Modifier le module $line[name]\"></a>
				");
			}
				
			Print("						
					</td>
				</tr>
				</thead>
			");
	}
	mysql_close($connection);
	return;
}

################################################################################################################
Function show_new_modules()
{
	$mods = get_new_mods();
	if ($mods == -1)
		return;
	$nb = count($mods);
	$i = 0;
	while ($i < $nb)
	{
		$install_file = "../".$_SESSION['path_apps']."/".$mods[$i]."/install_mod.php";
		if (file_exists($install_file))
		{
			if (!chk_mod($install_file))
			{
				$ndescription = "<font color=red><b>Erreur dans le fichier de configuration!</b></font>";
				$class = "red";
			}
			else
			{
				require ($install_file);
				if (!is_compatible($compatibility))
				{
					$ndescription = "<font color=red><b>Version de module non compatible avec le syst&egrave;me install&eacute;!</b></font>";
					$class = "red";
				}
				else
				{
					$ndescription = $description;
					$class = "blue";
				}
			}
		}
		else
		{
			if ($mods[$i] == "install")
				$ndescription = "<font color=red><b>Vous devez supprimer ce r&eacute;pertoire!</b></font>";
			else
				$ndescription = "<font color=red><b>Fichier de configuration n'existe pas!</b></font>";
			$class = "red";
		}
		
		if (trim(@$version) == "")
			@$version = "";
		
		Print("
			<thead>
				<tr class=\"$class\">
				<td align=left><font color=darkblue><b>$mods[$i]</b></font></td>
				<td align=left valign=top>$ndescription</td>
				<td align=left valign=top>$version</td>
				<td align=center>
			");
				
			if ($class != "red")
				Print("<a href=\"ipage.php?height=200&act=add&mid=$mods[$i]\" class=\"thickbox\" title=\"<font color=royalblue><b>Installer un module</b></font>\"><img src=\"$_SESSION[current_path]/images/application_add.png\" width=16 height=16 title=\"Installer le module $mods[$i]\"></a>");
					
			Print("						
					</td>
				</tr>
			</thead>
		");
		$i++;
	}
}

################################################################################################################
Function show_mod_edit($mid)
{
	$mod_infos = get_mod_infos($mid);
	
	Print("
		<div id=\"box\">
			<h3>$mod_infos[name]</h3>
			<form action=\"modules.php\" method=POST>
			<input type=hidden name=\"act\" value=\"edit_mod\">
			<input type=hidden name=\"mid\" value=\"$mid\">
			<input type=hidden name=\"actif2\" value=\"$mod_infos[actif]\">
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30%><b><font color=royalblue>MID:</font></b></td>
					<td><font color=#4B4B4B>$mid</font></td>
				</tr>
			</table>
			<hr color=#4B4B4B>
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30%><b><font color=royalblue>Status:</font></b></td>");
					if ($mod_infos['actif'] == "ok")
					Print("<td><font color=green><b>Valide</b></font> <img src=\"$_SESSION[path_images]/valid.png\"> - <input type=radio name=\"actif\" value=\"ko\"> D&eacute;sactiver</td>");
				else
					Print("<td><font color=red><b>D&eacute;sactiv&eacute;</b></font> <img src=\"$_SESSION[path_images]/stop.png\"> - <input type=radio name=\"actif\" value=\"ok\"> Activer</td>");
				Print("</tr>
			</table>
			<hr color=#4B4B4B>
			<b><font color=#4B4B4B>Utilisateurs annonymes</font></b>
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30%><b><font color=royalblue>Titre:</font></b></td>
					<td><font color=#4B4B4B><input type=text name=\"name_a\" value=\"$mod_infos[name_a]\"></font></td>
				</tr>
				<tr>
					<td width=30%><b><font color=royalblue>Liens:</font></b></td>
					<td><font color=#4B4B4B><input type=text name=\"link_a\" value=\"$mod_infos[link_a]\"></font></td>
				</tr>
				<tr>
					<td width=30%><b><font color=royalblue>Visible:</font></b></td>
					<td><select name=\"show_a\"");
						if ($mod_infos['show_a'] == "ok")
						{
							Print("
								<option value=\"ok\" selected>Oui</option>
								<option value=\"ko\">Non</option>
							");
						}
						else
						{
							Print("
								<option value=\"ok\">Oui</option>
								<option value=\"ko\" selected>Non</option>
							");
						}
							Print("</select></td>
				</tr>
			</table>
			<hr color=#4B4B4B>
			<b><font color=#4B4B4B>Utilisateurs enregistr&eacute;s</font></b>
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30%><b><font color=royalblue>Titre:</font></b></td>
					<td><font color=#4B4B4B><input type=text name=\"name_l\" value=\"$mod_infos[name_l]\"></font></td>
				</tr>
				<tr>
					<td width=30%><b><font color=royalblue>Liens:</font></b></td>
					<td><font color=#4B4B4B><input type=text name=\"link_l\" value=\"$mod_infos[link_l]\"></font></td>
				</tr>
				<tr>
					<td width=30%><b><font color=royalblue>Visible:</font></b></td>
					<td><select name=\"show_l\"");
						if ($mod_infos['show_l'] == "ok")
						{
							Print("
								<option value=\"ok\" selected>Oui</option>
								<option value=\"ko\">Non</option>
							");
						}
						else
						{
							Print("
								<option value=\"ok\">Oui</option>
								<option value=\"ko\" selected>Non</option>
							");
						}
							Print("</select></td>
				</tr>
			</table>
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td align=right><input type=submit value=\"Modifier\"></td>
				</tr>
			</table>
		</form>
		</div>
	");
	return;
}

################################################################################################################
Function show_mod_delete($mid)
{
	$mod_infos = get_mod_infos($mid);
	
	Print("
		<div id=\"box\">
			<h3>
			<table border=0>
				<tr>
					<td width=40><img src=\"$_SESSION[path_images]/large/delete_1.png\" width=40 height=40></td>
					<td><font size=3>Supprimer le module $mod_infos[name]</font></td>
				</tr>
			</table>
			</h3>
			<center>
				<br>
				<font color=\"red\"><b>Voulez vous continuer ?</b></font>
				<br>
				<table border=0 width=100%>
					<tr>
						<td width=50% align=right>
							<form action=\"modules.php\" method=POST>
								<table>
									<tr>
										<td align=right><input type=submit value=\"Annuler\"></td>
									</tr>
								</table>
							</form>
						</td>
						<td>
							<form action=\"modules.php\" method=POST>
							<input type=hidden name=\"act\" value=\"delete_mod\">
							<input type=hidden name=\"mid\" value=\"$mid\">
							<input type=hidden name=\"type\" value=\"$mod_infos[type]\">
							<table>
								<tr>
									<td><input type=submit value=\"Supprimer\"></td>
								</tr>
							</table>
							</form>
						</td>
					</tr>
				</table>
			</center>
		</div>
	");
	return;
}

################################################################################################################
Function show_mod_rights($mid)
{
	imports("odt_frm_php.users");
	$mod_infos = get_mod_infos($mid);
	
	Print("
		<div id=\"box\">
			<h3>$mod_infos[name]</h3>
			<form action=\"modules.php\" method=POST>
			<input type=hidden name=\"act\" value=\"rights_mod\">
			<input type=hidden name=\"mid\" value=\"$mid\">
			<input type=hidden name=\"type\" value=\"deluid\">
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td valign=top width=30%><b><font color=royalblue>Utilisateurs authoris&eacute;s:</font></b></td>
					<td width=30%>");
						show_list(get_users_mod($mid), "users");
					Print("</td>
					<td align=left><input type=submit value=\"Supprimer\"></td>
				</tr>
			</table>
			</form>
			<form action=\"modules.php\" method=POST>
			<input type=hidden name=\"act\" value=\"rights_mod\">
			<input type=hidden name=\"mid\" value=\"$mid\">
			<input type=hidden name=\"type\" value=\"delgid\">
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td valign=top width=30%><b><font color=royalblue>Groupes authoris&eacute;s:</font></b></td>
					<td width=30%>");
						show_list(get_groups_mod($mid), "groups");
					Print("</td>
					<td align=left><input type=submit value=\"Supprimer\"></td>
				</tr>
			</table>
			</form>
			<hr color=#4B4B4B>
			<form action=\"modules.php\" method=POST>
			<input type=hidden name=\"act\" value=\"rights_mod\">
			<input type=hidden name=\"mid\" value=\"$mid\">
			<input type=hidden name=\"type\" value=\"adduid\">
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td valign=top width=30%><b><font color=royalblue>Ajouter un utilisateur:</font></b></td>
					<td width=30%>");
						show_list(get_users(), "users");
					Print("</td>
					<td align=left><input type=submit value=\"Ajouter\"></td>
				</tr>
			</table>
			</form>
			<form action=\"modules.php\" method=POST>
			<input type=hidden name=\"act\" value=\"rights_mod\">
			<input type=hidden name=\"mid\" value=\"$mid\">
			<input type=hidden name=\"type\" value=\"addgid\">
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td valign=top width=30%><b><font color=royalblue>Ajouter un groupe:</font></b></td>
					<td width=30%>");
						show_list(get_groups(), "groups");
					Print("</td>
					<td align=left><input type=submit value=\"Ajouter\"></td>
				</tr>
			</table>
			</form>
		</div>
	");
	return;
}

################################################################################################################
Function show_mod_add($mod)
{
	Print("
		<br><br><br>
		<center>
			<table cellpadding=0 cellspcing=0 border=0 width=100%>
				<tr>
					<td width=30% align=right><img src=\"$_SESSION[current_path]/images/wait_1.gif\"></td>
					<td width=70% align=left><b>Installation du module en cours, veuillez patienter...</b></td>
				</tr>
			</table>
		</center>
	");
	$get_result = install_mod($mod);
	Print("<script language=JavaScript>setTimeout(\"document.location = 'modules.php?gr=$get_result'\", 3000)</script>");
	return;
}

################################################################################################################
Function show_link_add()
{
	Print("
		<div id=\"box\">
			<h3>Nouveau lien</h3>
				<form action=\"modules.php\" method=POST>
				<input type=hidden name=\"act\" value=\"link_add\">
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td>Titre: </td>
					<td><input type=\"text\" class=\"textbox1\" name=\"title\"></td>
				</tr>
				<tr>
					<td>Lien: </td>
					<td><input type=\"text\" class=\"textbox1\" name=\"link\"></td>
					<td><input type=submit value=\"Ajouter\"></td>
				</tr>
			</table>
				</form>
		</div>
	");
	return;
}

?>